package com.cbs.android.component.storage.qiniu.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.cbs.android.component.applicationutils.Global;
import com.cbs.android.component.log.L;
import com.cbs.android.component.storage.qiniu.Qiniu;
import com.cbs.component.android.storage.storageinterface.StorageHandler;
import com.cbs.component.android.storage.storageinterface.StorageInterface;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getName();
    private StorageInterface storageInterface = new Qiniu();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Global.init(this);
        Global.setServerHost("http://service.guguxinge.com:8080");
    }

    public void upload(View view) {
        byte[] bytes = new byte[100];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte) i;
        }

        L.e("111", "size: " + ((Qiniu) storageInterface).uploaders.size());
        storageInterface.upload("user", "avatar", null, bytes, new StorageHandler() {
            @Override
            public void onSuccess(String id, String key, String result) {
                L.e(TAG, "success(" + id + "): " + key + ")\tresult: " + result);
            }

            @Override
            public void onException(String id, String key, Exception e) {
                L.e(TAG, "exception(" + id + ")", e);
            }

            @Override
            public void onProgress(String id, String key, double percent) {
                L.e(TAG, "progress(" + id + "): " + percent);
            }
        });
    }
}
